const buttons = document.querySelectorAll(".button");
const button_reset = document.querySelector(".button_reset");
const txt = document.querySelector(".txt")
const imgGif = document.querySelector(".img-gif")
console.log(buttons);

// 重置按钮的点击事件
button_reset.addEventListener("click", function () {
    buttons.forEach(function (item) {
        item.style.display = "inline-block"; // 显示所有按钮
    });
    button_reset.style.display = "none"; // 隐藏重置按钮
});

const ohyes = {
    text: "我知道你会同意的。",
    image: "./images/cat-yes.gif"
}

const alternatives = [
    { text: "", image: "./images/cat-01.gif" },
    { text: "保证这将令人难忘", image: "./images/cat-02.gif" },
    { text: "再想想，亲亲", image: "./images/cat-03.gif" },
    { text: "来吧，你一定需要我", image: "./images/cat-04.gif" },
    { text: "不要给自己找借口", image: "./images/cat-05.gif" }
]

let idx = 0

function updateDisplay(o) {
    imgGif.src = o.image
    txt.innerHTML = o.text
}

button_reset.addEventListener("click", function () {
    idx = 0
    updateDisplay(alternatives[idx])
    buttons.forEach(function (item) {
        item.style.display = "inline-block"
    })
    button_reset.style.display = "none"
})

// 普通按钮的点击事件
buttons.forEach(function (btn) {
    btn.addEventListener("click", function () {
        if (btn.id == "y") {
            buttons.forEach(function (item) {
                item.style.display = "none"; // 隐藏所有按钮
            });
            updateDisplay(ohyes)
            const sound = document.getElementById("h")
            sound.volume = 0.3
            sound.play()
        }
        if (btn.id == "n") {
            const sound = document.getElementById("s")
            sound.currentTime = 0
            sound.volume = 0.3
            sound.play()
            idx += 1
            if (idx < alternatives.length) {
                updateDisplay(alternatives[idx])
            } else {
                buttons.forEach(function (item) {
                    item.style.display = "none"; // 隐藏所有按钮
                });
                button_reset.style.display = "inline-block"; // 显示重置按钮

            }


        }
    });
});